package org.teamh.gui.mapeditor.popups;

import org.teamh.gui.GUI;

import de.lessvoid.nifty.builder.PanelBuilder;
import de.lessvoid.nifty.builder.PopupBuilder;
import de.lessvoid.nifty.controls.button.builder.ButtonBuilder;
import de.lessvoid.nifty.controls.label.builder.LabelBuilder;
import de.lessvoid.nifty.elements.Element;

public class SavePopup {

	private GUI gui;
	private Element savePopup;
	
	public SavePopup(GUI gui) {
		this.gui = gui;
		
		initPopup();
	}
	
	private void initPopup() {
		new PopupBuilder("save_map_popup") {{
			backgroundColor("#00000099");
			childLayoutCenter();
			panel(new PanelBuilder() {{
				childLayoutVertical();
				style("nifty-panel");
				width("500px");
				height("200px");
				
				//upper panel for displaying text
				panel(new PanelBuilder() {{
					childLayoutCenter();
					valignCenter();
					height("90px");
					width("450px");
					control(new LabelBuilder() {{
						width("450px");
						text("Current changes will be discarded. Do you want to save?");
						color("#ffffff");
					}});
				}});
				//end upper panel
				
				//lower panel for displaying buttons
				panel(new PanelBuilder() {{
					childLayoutHorizontal();
					valignCenter();
					height("90px");
					width("450px");
					
					panel(new PanelBuilder() {{
						width("225px");
						height("90px");
						childLayoutCenter();
						
						control(new ButtonBuilder("save_map", "Yes") {{
							visibleToMouse();
							interactOnClick("saveCurrentChanges()");
						}});
					}});
					
					panel(new PanelBuilder() {{
						width("225px");
						height("90px");
						childLayoutCenter();
						
						control(new ButtonBuilder("save_map_cancel", "No") {{
							visibleToMouse();
							interactOnClick("closeSavePopup()");
						}});
					}});
				}});
				//end lower panel
			}});
		}}.registerPopup(gui.getNifty());
		
		setSavePopup(gui.getNifty().createPopup("save_map_popup"));
	}

	public Element getSavePopup() {
		return savePopup;
	}

	public void setSavePopup(Element savePopup) {
		this.savePopup = savePopup;
	}
}